//
//  WuLiRequestTypeStarAPI.m
//  WULIHH
//
//  Created by tang on 16/4/20.
//  Copyright © 2016年 tang. All rights reserved.
//

#import "WuLiRequestTypeStarAPI.h"
#import "Header.h"
#import "AFNetworking.h"
#import "UserInfoModel.h"

@implementation WuLiRequestTypeStarAPI



+ (id)requestStarType:(NSString *)StarID
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    [manager.requestSerializer setValue:[UserInfoModel tokenString] forHTTPHeaderField:@"X-AUTH-TOKEN"];
    [manager.requestSerializer setValue:appVersion forHTTPHeaderField:@"X-APP-VERSON"];
    [manager.requestSerializer setValue:typetext forHTTPHeaderField:@"Content-Type"];
    
    NSString *httpString = [NSString stringWithFormat:@"%@%@%@/%@",hostName, addStarAPI, StarID, mingxingbiaoqianAPI];
    
    
    NSLog(@"%@", httpString);
    [manager GET:httpString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        // 这里可以获取到目前的数据请求的进度
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 请求成功，解析数据
        //        NSLog(@"%@", responseObject);
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
                [[NSNotificationCenter defaultCenter] postNotificationName:mingxingbiaoqian object:nil userInfo:dic];
//        NSLog(@"%@", dic);
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 请求失败
        NSLog(@"%@", [error localizedDescription]);
    }];

    return self;
}







//搜索标签下的图片
+ (id)requestStarType:(NSString *)StarID withTags:(NSString *)tagString withPage:(NSString *)page
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    [manager.requestSerializer setValue:[UserInfoModel tokenString] forHTTPHeaderField:@"X-AUTH-TOKEN"];
    [manager.requestSerializer setValue:appVersion forHTTPHeaderField:@"X-APP-VERSON"];
    [manager.requestSerializer setValue:typetext forHTTPHeaderField:@"Content-Type"];
    
    NSString *httpString = [NSString stringWithFormat:@"%@%@%@%@/%@/%@?page=%@",hostName, addStarAPI, StarID,@"/tag", tagString ,mingxingbiaoqianAPI, page];
    
    
    NSLog(@"%@", httpString);
    [manager GET:httpString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        // 这里可以获取到目前的数据请求的进度
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 请求成功，解析数据
        //        NSLog(@"%@", responseObject);
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"typework" object:nil userInfo:dic];
//                NSLog(@"%@", dic);
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 请求失败
        NSLog(@"%@", [error localizedDescription]);
    }];

    return self;
}




//收藏图片
+ (id)requestFavImageWith:(NSString *)imageIDString
{
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    
    [manager.requestSerializer setValue:[UserInfoModel tokenString] forHTTPHeaderField:@"X-AUTH-TOKEN"];
    [manager.requestSerializer setValue:appVersion forHTTPHeaderField:@"X-APP-VERSON"];
    [manager.requestSerializer setValue:typetext forHTTPHeaderField:@"Content-Type"];
    
    NSString *httpString = [NSString stringWithFormat:@"%@%@%@%@/%@",hostName, addStarAPI, @"material/",imageIDString, @"collect/"];
    
    
    NSLog(@"%@", httpString);
    [manager POST:httpString parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        // 这里可以获取到目前的数据请求的进度
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 请求成功，解析数据
        //        NSLog(@"%@", responseObject);
        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:nil];
//        [[NSNotificationCenter defaultCenter] postNotificationName:mingxingbiaoqian object:nil userInfo:dic];
                NSLog(@"%@", dic);
        
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 请求失败
        NSLog(@"%@", [error localizedDescription]);
    }];

    return self;
}

@end
